//
//  UpSizeVC.m
//  jingdongfang
//
//  Created by MTiMac01 on 2017/8/28.
//  Copyright © 2017年 LJL. All rights reserved.
//

#import "UpSizeVC.h"

@interface UpSizeVC ()<UITableViewDelegate, UITableViewDataSource>
{
    UITextField *widTextF;
    UITextField *heiTextF;
}

@property (weak, nonatomic) IBOutlet UITableView *tableV;

@end

@implementation UpSizeVC

- (void)viewDidLoad
{
    [super viewDidLoad];
//    self.title = @"尺寸";
    self.title = NSLocalizedString(@"Width cm/Height cm", nil);
    UIButton *right = [UIButton buttonWithType:UIButtonTypeCustom];
    right.frame = CGRectMake(0, 0, 50, 50);
//    [right setTitle:@"确定" forState:UIControlStateNormal];
    [right setTitle:NSLocalizedString(@"Confirm", nil) forState:UIControlStateNormal];
    [right setTitleColor:[UIColor appColor] forState:UIControlStateNormal];
    [right addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:right];
    self.tableV.backgroundColor = [UIColor c2Color];
    self.tableV.separatorStyle = UITableViewCellSeparatorStyleNone;
}

- (void)rightBtnClick
{
    NSString *sizeSt = @"";
    if (widTextF.text.length && heiTextF.text.length)
    {
        sizeSt = [NSString stringWithFormat:@"%@x%@cm", widTextF.text, heiTextF.text];
    }
    self.sureBlock(sizeSt, widTextF.text, heiTextF.text);
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

#pragma mark - UITableViewDelegate, UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.font = [UIFont systemFontOfSize:16];
    cell.textLabel.textColor = [UIColor c4Color];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:16];
    cell.detailTextLabel.textAlignment = NSTextAlignmentRight;
    cell.detailTextLabel.textColor = [UIColor lightGrayColor];
    CGFloat x = cell.separatorInset.left;
    
    if (indexPath.section==0)
    {
        if (indexPath.row == 0)
        {
//            cell.textLabel.text = @"宽 cm";
            cell.textLabel.text = [NSString stringWithFormat:@"%@ cm",NSLocalizedString(@"Width", nil)];

            UITextField *textfield = [[UITextField alloc]init];
            textfield.width = 120;
            textfield.height = cell.height - 1;
            textfield.centerY = cell.centerY;
            textfield.borderStyle = UITextBorderStyleNone;
//            textfield.placeholder = @"请输入";
            textfield.placeholder = [NSString stringWithFormat:@"%@ cm",NSLocalizedString(@"Width", nil)];
            textfield.keyboardType = UIKeyboardTypeNumberPad;
            textfield.font = [UIFont systemFontOfSize:16];
            textfield.textColor = [UIColor c5Color];
            textfield.textAlignment = NSTextAlignmentRight;
            widTextF = textfield;
            cell.accessoryView = textfield;
        }
        else if (indexPath.row == 1)
        {
//            cell.textLabel.text = @"高 cm";
            cell.textLabel.text = [NSString stringWithFormat:@"%@ cm",NSLocalizedString(@"Height", nil)];
            UITextField *textfield = [[UITextField alloc]init];
            textfield.width = 120;
            textfield.height = cell.height - 1;
            textfield.centerY = cell.centerY;
            textfield.borderStyle = UITextBorderStyleNone;
//            textfield.placeholder = @"请输入";
            textfield.placeholder = [NSString stringWithFormat:@"%@ cm",NSLocalizedString(@"Height", nil)];
            textfield.keyboardType = UIKeyboardTypeNumberPad;
            textfield.font = [UIFont systemFontOfSize:16];
            textfield.textColor = [UIColor c5Color];
            textfield.textAlignment = NSTextAlignmentRight;
            heiTextF = textfield;
            cell.accessoryView = textfield;
            UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(x, 0, KSCREENWIDTH-x-x, .5)];
            line.backgroundColor = [UIColor c6Color];
            [cell.contentView addSubview:line];
        }
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}
@end
